Component({
  data: {
    active:0,
    list: [
      {
        label:"首页",
        model:"home",
        icon:'home',
        path:"/pages/home/home",
      },{
        label:"所有服务",
        model:"serve",
        icon:'app',
        path:"/pages/serve/serve",

      },{
        label:"购物车",
        model:"shoppingCart",
        icon:'cart',
        path:"/pages/shoppingCart/shoppingCart",

      },{
        label:"我的",
        model:"user",
        icon:'user',
        path:"/pages/user/user",

      },
    ]
  },

  methods: {
    init() {
      const page = getCurrentPages().pop();
      const route = page ? page.route.split('?')[0] : '';
      const active = this.data.list.findIndex(
        (item) =>
          (item.path.startsWith('/') ? item.path.substr(1) : item.path) ===
          `${route}`,
      );
      this.setData({ active });
    },
    onChange(event) {
      this.setData({ active: event.detail.value });
      wx.switchTab({
        url: this.data.list[event.detail.value].path.startsWith('/')
          ? this.data.list[event.detail.value].path
          : `/${this.data.list[event.detail.value].path}`,
      });
    },
  }
});